package org.jeecg.demo.wx.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import org.jeecg.common.api.vo.Result;
import org.jeecg.demo.wx.request.WXLoginRequest;
import org.jeecg.demo.wx.service.WXLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述
 * 微信登录控制器
 *
 * @author: zgq
 * @date: 2024年01月28日 19:49
 */
@RestController
@RequestMapping("/wx")
@Api(tags = "微信登录接口")
public class WXLoginController {
    @Autowired
    private WXLoginService wxLoginService;

    @PostMapping("/login")
    public Result<JSONObject> login(@RequestBody @Validated WXLoginRequest request) {
        try {
            Result<JSONObject> result = wxLoginService.login(request);
            return result.success("登陆成功");
        } catch (Exception e) {
            return Result.error(401, "登陆失败");
        }

    }
}
